cmake_minimum_required(VERSION 3.16)
project(DDM VERSION 1.0.0 LANGUAGES CXX)

# 设置C++标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 自动检测Qt路径
if(WIN32)
    # 检查常见的Qt安装路径
    set(QT_PATHS 
        "C:/Qt/6.9.1/msvc2022_64"
        "C:/Qt/6.8.0/msvc2022_64"
        "C:/Qt/6.7.0/msvc2022_64"
        "C:/Qt/6.9.1/msvc2019_64"
        "C:/Qt/6.8.0/msvc2019_64"
        "C:/Qt/6.7.0/msvc2019_64"
    )
    
    foreach(QT_PATH ${QT_PATHS})
        if(EXISTS ${QT_PATH})
            list(APPEND CMAKE_PREFIX_PATH ${QT_PATH})
            break()
        endif()
    endforeach()
endif()

# 查找Qt库
find_package(Qt6 REQUIRED COMPONENTS Core Widgets Network)

# 启用自动处理MOC, UIC, RCC
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

# 设置包含目录
include_directories(include)

# 设置源文件
set(SOURCES
    src/main.cpp
    src/mainwindow.cpp
    src/downloadmanager.cpp
    src/downloaditem.cpp
    src/settingsmanager.cpp
    src/settingsdialog.cpp
    src/downloadhistory.cpp
    src/notificationmanager.cpp
)

set(HEADERS
    include/mainwindow.h
    include/downloadmanager.h
    include/downloaditem.h
    include/settingsmanager.h
    include/settingsdialog.h
    include/downloadhistory.h
    include/notificationmanager.h
)

# 添加资源文件
set(RESOURCES resources/resources.qrc)

# 创建可执行文件
add_executable(${PROJECT_NAME} 
    ${SOURCES}
    ${HEADERS}
    ${RESOURCES}
)

# 设置Windows图标 (仅适用于Windows)
if(WIN32)
    target_sources(${PROJECT_NAME} PRIVATE resources/app.rc)
endif()

# 链接Qt库
target_link_libraries(${PROJECT_NAME} 
    Qt6::Core
    Qt6::Widgets
    Qt6::Network
)

# 设置编译特性
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)

# 设置输出目录
set_target_properties(${PROJECT_NAME} PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)

# 设置GUI应用程序类型(Windows)
if(WIN32)
    set_target_properties(${PROJECT_NAME} PROPERTIES
        WIN32_EXECUTABLE ON
    )
endif()